﻿Imports System.Globalization
Imports System.Runtime.Serialization

Namespace Model

    <Datacontract()> _
    Public Class Station
        Implements ICloneable

        <DataMember()> _
        Private _Id As String
        ''' <summary>
        ''' 放送局ID
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property Id() As String
            Get
                Return _Id
            End Get
            Set(ByVal value As String)
                _Id = value
            End Set
        End Property

        ''' <summary>
        ''' 放送局の種類
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public ReadOnly Property Kind() As StationKind
            Get
                If Me.Id.StartsWith("ch", StringComparison.Ordinal) Then
                    Return StationKind.Channel
                ElseIf Me.Id.StartsWith("co", StringComparison.Ordinal) Then
                    Return StationKind.Community
                Else
                    Return StationKind.None
                End If
            End Get
        End Property

        <DataMember()> _
        Private _Name As String = ""
        ''' <summary>
        ''' 放送局名
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property Name() As String
            Get
                Return _Name
            End Get
            Set(ByVal value As String)
                _Name = value
            End Set
        End Property

        <DataMember()> _
        Private _UpdateDateTime As DateTime
        ''' <summary>
        ''' 放送局ページの更新日時
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property UpdateDateTime() As DateTime
            Get
                Return _UpdateDateTime
            End Get
            Set(ByVal value As DateTime)
                _UpdateDateTime = value
            End Set
        End Property

        <DataMember()> _
        Private _Rating As Integer
        ''' <summary>
        ''' ユーザーによる放送局の評価
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property Rating() As Integer
            Get
                Return _Rating
            End Get
            Set(ByVal value As Integer)
                _Rating = value
            End Set
        End Property

        <DataMember()> _
        Private _IsAlertTarget As Boolean
        ''' <summary>
        ''' 通知対象かどうか
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property IsAlertTarget() As Boolean
            Get
                Return _IsAlertTarget
            End Get
            Set(ByVal value As Boolean)
                _IsAlertTarget = value
            End Set
        End Property

        <DataMember()> _
        Private _Level As Integer
        ''' <summary>
        ''' コミュニティのレベル
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property Level() As Integer
            Get
                Return _Level
            End Get
            Set(ByVal value As Integer)
                _Level = value
            End Set
        End Property

        <DataMember()> _
        Private _MemberCount As Integer
        ''' <summary>
        ''' 参加メンバー数
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property MemberCount() As Integer
            Get
                Return _MemberCount
            End Get
            Set(ByVal value As Integer)
                _MemberCount = value
            End Set
        End Property

        <DataMember()> _
        Private _Note As String = ""
        ''' <summary>
        ''' ユーザーによる放送局のメモ
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property Note() As String
            Get
                Return _Note
            End Get
            Set(ByVal value As String)
                _Note = value
            End Set
        End Property

        <DataMember()> _
        Private _PluginGuids As New List(Of Guid)
        Public ReadOnly Property PluginGuids() As IList(Of Guid)
            Get
                Return _PluginGuids
            End Get
        End Property

#Region "Shared Properties"

        Public Shared ReadOnly Property ChannelUriFormat() As String
            Get
                Return My.Settings.ChannelIconUriFormat
            End Get
        End Property

        Public Shared ReadOnly Property ChannelIconUriFormat() As String
            Get
                Return My.Settings.ChannelIconUriFormat
            End Get
        End Property

        Public Shared ReadOnly Property CommunityUriFormat() As String
            Get
                Return My.Settings.CommunityIconUriFormat
            End Get
        End Property

        Public Shared ReadOnly Property CommunityIconUriFormat() As String
            Get
                Return My.Settings.CommunityIconUriFormat
            End Get
        End Property

#End Region

        Public ReadOnly Property Uri() As Uri
            Get
                Select Case Me.Kind
                    Case StationKind.Channel
                        Return New Uri(String.Format(CultureInfo.InvariantCulture, My.Settings.ChannelUriFormat, Me.Id))
                    Case StationKind.Community ' Community
                        Return New Uri(String.Format(CultureInfo.InvariantCulture, My.Settings.CommunityUriFormat, Me.Id))
                    Case StationKind.Official
                        Throw New NotImplementedException
                    Case Else
                        Throw New NotSupportedException
                End Select
            End Get
        End Property

        <DataMember()> _
        Private _IconUri As Uri
        Public Property IconUri() As Uri
            Get
                Return _IconUri
            End Get
            Set(ByVal value As Uri)
                _IconUri = value
            End Set
        End Property

        Public Function Clone() As Object Implements System.ICloneable.Clone
            Dim station = New Station
            With station
                .Id = Me.Id
                .Name = Me.Name
                .UpdateDateTime = Me.UpdateDateTime
                .Note = Me.Note
                .IsAlertTarget = Me.IsAlertTarget
                .MemberCount = Me.MemberCount
                .Level = Me.Level
                .Rating = Me.Rating
                .IconUri = Me.IconUri
            End With

            For Each i In Me.PluginGuids
                station.PluginGuids.Add(i)
            Next

            Return station
        End Function

    End Class





End Namespace
